package com.fary.aop;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;

@Component
@Aspect
public class ControllerCrossAspect {

    //对包下所有的controller结尾的类的所有方法增强
    private final String executeExpr = "execution(* com.fary.api.*.*(..)))";


    @After(executeExpr)
    public void afterAdvice() {
        HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        resp.setHeader("Access-Control-Allow-Origin", "*");
    }

}
